The following floating palette contains a text field that shows the contents of the selected Script marker (the yellow icon that appears in the Document window to mark the location of a script). If no Script marker is selected, a layer that contains the text (no script selected)
appears.
<html><head><title>Script Editor</title><script language="JavaScript"> function selectionChanged(){ /* get the selected node */ var theDOM = dw.getDocumentDOM(); var theNode = theDOM.getSelectedNode(); /* check to see if the node is a script marker */ if (theNode.nodeType == Node.ELEMENT_NODE && theNode.tagName == "SCRIPT"){ document.layers['scriptlayer'].visibility = 'visible'; document.layers['scriptlayer'].document.theForm.scriptCode.value = theNode.innerHTML; document.layers['blanklayer'].visibility = 'hidden'; }else{ document.layers['scriptlayer'].visibility = 'hidden'; document.layers['blanklayer'].visibility = 'visible'; } } /* update the document with any changes made by the user in the textarea */ function updateScript(){ var theDOM = dw.getDocumentDOM(); var theNode = dw.getSelectedNode(); theNode.innerHTML = document.layers['scriptlayer'].document.theForm.scriptCode.value; } </script></head> <body><div id="blanklayer" style="position:absolute; width:422px; height:181px; z-index:1; left: 8px; top: 11px; visibility: hidden"><center><br><br><br><br><br>(no script selected) </center></div> <div id="scriptlayer" style="position:absolute; width:422px; height:181px; z-index:1; left: 8px; top: 11px; visibility: visible"><form name="theForm"><textarea name="scriptCode" cols="80" rows="20" wrap="VIRTUAL" onBlur="updateScript()"></textarea></form></div> </body></html>
Remember that it is not sufficient to save this code in a file called scriptEditor.htm in the Configuration/Floaters folder; you must also call dw.setFloaterVisibility('scriptEditor',true)
, or dw.toggleFloater('scriptEditor')
from somewhere in order to load the floater and make it visible. The most obvious place from which to do this is the Window menu in menus.xml file. The menuitem
tag might look like this:
<menuitem name="Script Editor" enabled="true" command="dw.toggleFloater('scriptEditor')" checked="dw.getFloaterVisibility('scriptEditor')" />